@isTest
private class OpportunityNewOverrideControllerTest {
	
	private static ID curAccId;
	private static ID curOppId;
	
	private static string recordTypeAdvancedAds   	  = RecordTypeHelper.GetRecordTypeId('Opportunity', 'Advanced Ad Solutions');
    private static string recordTypeLocalAdvertiser   = RecordTypeHelper.GetRecordTypeId('Opportunity', 'Local Advertiser');
    
	private static User userAAS;
	private static User userLocal;
	
	private static void init(){
		  string[] profileList = new String [] {'AAS Operations Team','Advanced Ad Solutions (Delegated Admin)','Advanced Ad Solutions (Client Services)','SFA OOR Sales Operations'};
		  list<Profile> pfs = [select ID, Name from Profile where Name  IN :profileList];
		  
	      //Create a map between the Profile Name and Id for easy retrieval
       	  Map<String,String> profiles = new Map<String,String>{};
     	  for(Profile pf: pfs)
        	profiles.put(pf.Name,pf.Id);
     
		  
	      userAAS = new User();
	      userAAS.UserName = 'AASUser@att.com';
	      userAAS.LastName = 'Test User1';
	      userAAS.Email = 'test1@attinteractive.com';
	      userAAS.Alias = 'testAAS' ;
	      userAAS.CommunityNickname = 'xyaz_1234556';
	      userAAS.TimeZoneSidKey = 'America/Los_Angeles';
	      userAAS.LocaleSidKey = 'en_US';
	      userAAS.EmailEncodingKey = 'UTF-8';
	      userAAS.ProfileId = profiles.get('AAS Operations Team');	      
	      userAAS.LanguageLocaleKey = 'en_US';
	      userAAS.IsActive = true;
	      insert userAAS;
		
	      userLocal = new User();
	      userLocal.UserName = 'LocalUser@att.com';
	      userLocal.LastName = 'Test User2';
	      userLocal.Email = 'test2@attinteractive.com';
	      userLocal.Alias = 'testLOC' ;
	      userLocal.CommunityNickname = 'xyaz_1234557';
	      userLocal.TimeZoneSidKey = 'America/Los_Angeles';
	      userLocal.LocaleSidKey = 'en_US';
	      userLocal.EmailEncodingKey = 'UTF-8';
	      userLocal.ProfileId = profiles.get('SFA OOR Sales Operations');	      
	      userLocal.LanguageLocaleKey = 'en_US';
	      userLocal.IsActive = true;
	      insert userLocal;

	    
	}
	public static testMethod void testAASOpportunity() {
		init();
				
		System.runAs(userAAS)
    	{
			PageReference pageRef = Page.OpportunityNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeAdvancedAds);
			ApexPages.currentPage().getParameters().put('retURL', '/006');
			Opportunity opp = new Opportunity();
			ApexPages.StandardController sc = new ApexPages.StandardController(opp);
			
			OpportunityNewOverrideController controller = new OpportunityNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirected to standard create opportunity page
			System.assert(nextPage.getUrl().Contains('apex/selectmasterclient'));
			
    	}
  	}	
	 public static testMethod void testLocalAdvertiserOpportunity() {
		init();
				
		System.runAs(userLocal)
    	{
			PageReference pageRef = Page.OpportunityNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeLocalAdvertiser);
			ApexPages.currentPage().getParameters().put('retURL', '/006');
			Opportunity opp = new Opportunity();
			ApexPages.StandardController sc = new ApexPages.StandardController(opp);
			
			OpportunityNewOverrideController controller = new OpportunityNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirected to standard create opportunity page
			System.assert(nextPage.getUrl().Contains('/006/e'));
			
    	}
	}
	
	
		

}